<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<base href="<%=request.getContextPath()%>/">	
		<link rel="stylesheet" href="about/css/bootstrap.min.css">
		<link href="about/css/myCss.css" type="text/css" rel="stylesheet">
		<link href="about/css/main.css" type="text/css" rel="stylesheet">
		<link href="about/css/base.css" type="text/css" rel="stylesheet">
		<!--按钮样式表-->
		<link href="about/css/btn.css" type="text/css" rel="stylesheet">
		<link href="about/css/css.css" type="text/css" rel="stylesheet">
		<link href="about/css/index.css" type="text/css" rel="stylesheet">
		<link href="about/css/search.css" type="text/css" rel="stylesheet">
		<script src="about/js/jquery.min.js"></script>
		<script src="about/js/bootstrap.min.js"></script>
		<script src="about/js/jQuery.rTabs.js"></script>
		<script src="about/js/common.js"></script>
		<title>今日护理安排</title>
		<script type="text/javascript">
			$(function() {
				$formModal = $("#formModal");
				$formModal.click(addProject);
				$addBtn = $("#addBtn");
				$addBtn.click(projectList);
			})

			var remove = function(customerId, nurContentId) {
				var url = "/nurrecord/api/projectDelete";
				$.get(url, {
						"customerId": customerId,
						"nurContentId": nurContentId
					},
					function(resp) {
						console.log(resp);
						if(resp.code == "ok") {
							/* setTimeout(function(){
								location.href="http://127.0.0.1:8080/beadhouse/api/nurrecord/projectList?customerId"+$('#customerId').val();
							},500) */
							toast("成功");
							$("#selectBut").click();
						} else {
							toast(resp.message);
						}
					})
			}

			var projectList = function() {
				var url = "/nurrecord/nurlevel/list.do";
				
				var nurLevelId = $("#nurLevelIdInp").val();
				$.get(url,{
					"nurLevelId":nurLevelId
				} ,function(resp) {
					if(resp.code == "ok") {
						var rows = resp.data.rows;
						var html = printOption(rows);
						$("#serviceProject").html(html);
					}else{
						toast(resp.message);
					}
				})
			}

			var printOption = function(result) {
				var html = "";
				for(var i = 0; i < result.length; i++) {
					html += printOne(result[i]);
				}
				return html;
			}
			/**
			 * 新增角色一行
			 */
			var printOne = function(result) {
				var html = "<option name='";
				html += result.id;
				html += "'>";
				html += result.name;
				html += "</option>";
				/*<option id="">测量血压</option>*/
				return html;
			}

			var addProject = function() {
				var src = window.location.href;
				var index = src.lastIndexOf("=") + 1;
				customerId = src.substring(index);
				
				var url = "/nurrecord/api/projectAdd";
				var nurContentId = $("#serviceProject option:selected").attr("name");
				$.get(url, {
						"customerId": customerId,
						"nurContentId": nurContentId,
						"nurContentName": $("#serviceProject").val(),
						"startTime": $("#startTime").val(),
						"content": $("#serviceContent").val()
					},
					function(resp) {
						console.log(resp);
						if(resp.code == "ok") {
							 $("#selectBut").click(); //差customerId
						} else {
							toast(resp.message);
						}

					})
			}

			var ok = function(customerId, nurContentId) {
				var url = "/nurrecord/api/projectSet";
				$.get(url, {
						"customerId": customerId,
						"nurContentId": nurContentId
					},
					function(resp) {
						if(resp.code == "ok") {
							$(this).parentsUntil("tbody").css("background-color", "gray");
							/* setTimeout(function(){
								location.href="http://127.0.0.1:8080/beadhouse/api/nurrecord/projectList?customerId"+$('#customerId').val();
							},500) */
							toast("成功");
						} else {
							toast(resp.message);
						}
					})
			}
			//$(this).attr('disabled',"true");

			/* $('.remove').click(function() {
				$(this).parentsUntil("tbody").remove();
			}); */
		</script>
	</head>

	<body>
	<h5><%String customerId = request.getParameter("customerId"); %></h5>
	<h5><%String nurLevelId = request.getParameter("nurLevelId"); %></h5>
	<h5><%=customerId %></h5>
		<div class="hljl_add page">
			<div style="height: 800px;" class="col-md-12 pd0 CPJBXX_RightContentBody mt20">
				<div class="col-md-3 pd0 fmt5">
					<div class="input-group inputWidth_search">
						<form action="nurrecord/projectList.do" style="display: flex;">
							<input name="key" type="text" class="form-control" placeholder="护理项目">
							<input id="nurLevelIdInp" name="nurLevelId" hidden value="<%=nurLevelId %>">
							<input name="customerId" hidden value="<%=customerId %>">
							<button id="selectBut" class="btn btn-success">查询</button>
						</form>
					</div>

				</div>
				<div class="col-md-1 pd0 fmt5">
					<button id="addBtn" class="btn btn-primary" data-toggle="modal" data-target=".myModal1">
					<span class="glyphicon glyphicon-plus"></span>&nbsp;添加护理项目
				</button>
				</div>
				<!--
                	作者：847534693@qq.com
                	时间：2018-10-23
                	描述：模态框
                -->

				<div class="modal fade myModal1">
					<div class="modal-dialog">
						<div class="modal-content" style="width: 100%;">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">
									<span aria-hidden="true">&times;</span>
								</button>
								<span class="glyphicon glyphicon-plus"></span>&nbsp;【添加-护理项目】
							</div>

							<div class="modal-body clearfix" style="height: auto;">
								<div class="col-md-12 pd0">
									<div class="col-md-1 pd0 mt10"></div>

									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;服务项目：</span>
												<select id="serviceProject" class="form-control">
													<!--<option id="">测量血压</option>
													<option>吸氧</option>-->
												</select>
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;执行时间：</span>
												<input id="startTime" type="time" class="form-control">
											</div>
										</div>
									</div>
								</div>

								<div class="col-md-12 pd0 mt10">
									<div class="col-md-1 pd0"></div>
									<div class="col-md-10 pd0">
										<div class="col-md-12 pd0">
											<div class="input-group inputWidth">
												<span class="input-group-addon titleWidth">&nbsp;&nbsp;服务内容：</span>
												<input id="serviceContent" class="form-control">
											</div>
										</div>
									</div>
									<div class="col-md-1 pd0"></div>
								</div>
							</div>

							<input hidden id="customerId" value="${date.data.rows[0].customerId}" />
							<input hidden id="nurContentId" value="4" />
							<div class="modal-footer mt20">
								<button id="formModal" type="button" class="btn btn-primary" data-dismiss="modal">确定</button>
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
							</div>
						</div>
					</div>
				</div>

				<div class="col-md-12 pd0 fmt10">
					<hr class="commonHRCss" />
				</div>
				<div class="col-md-12 pd0">
					<div class="tab" id="tab4">

						<div class="tab-con">
							<div class="j-tab-con">
								<div class="tab-con-item" style="display: block;">
									<div class="col-md-12 pd10">
										<div class="col-md-12 pd0">
											<table class="table">
												<thead>
													<tr>
														<th>
															<center>
																<font color="#000">序号</font>
															</center>
														</th>
														<th>
															<center>
																<font color="#000">护理项目</font>
															</center>
														</th>

														<th>
															<center>
																<font color="#000">执行时间</font>
															</center>
														</th>
														<th>
															<center>
																<font color="#000">护理内容</font>
															</center>
														</th>
														<th>
															<center>
																<font color="#000">操作</font>
															</center>
														</th>
													</tr>
												</thead>
												<tbody>
													<c:if test="${date.data.pageNo!=date.data.totalPages}">
														<c:forEach var="i" begin="0" end="${date.data.pageSize-1}" step="1">
															<tr>
																<td>
																	<font color="#000">${i+1}</font>
																</td>
																<td hidden>${date.data.rows[i].customerId}</td>
																<td>
																	<font color="#000">${date.data.rows[i].nurContentName}</font>
																</td>
																<td>
																	<font color="#000">
																		<fmt:formatDate value="${date.data.rows[i].startTime}" pattern="yyyy-MM-dd" />
																	</font>
																</td>
																<td>
																	<font color="#000">${date.data.rows[i].content}</font>
																</td>
																<td><input hidden id="customerId" value="${date.data.rows[i].customerId}" /> <input hidden id=nurContentId value="${date.data.rows[i].nurContentId}" />
																	<button onclick="ok(${date.data.rows[i].customerId},${date.data.rows[i].nurContentId})" class="btn btn-success">
																	<span class="glyphicon glyphicon-ok"></span>
																</button>
																	<button onclick="remove(${date.data.rows[i].customerId},${date.data.rows[i].nurContentId})" class="btn btn-danger">
																	<span class="glyphicon glyphicon-remove"></span>
																</button></td>
															</tr>
														</c:forEach>
													</c:if>

													<c:if test="${date.data.pageNo==date.data.totalPages}">
														<c:forEach var="i" begin="0" end="${date.data.totalRows-(date.data.totalPages-1)*date.data.pageSize-1}" step="1">
															<tr>
																<td>
																	<font color="#000">${i+1}</font>
																</td>
																<td hidden>${date.data.rows[i].customerId}</td>
																<td>
																	<font color="#000">${date.data.rows[i].nurContentName}</font>
																</td>
																<td>
																	<font color="#000">
																		<fmt:formatDate value="${date.data.rows[i].startTime}" pattern="yyyy-MM-dd HH:mm:ss" />
																	</font>
																</td>
																<td>
																	<font color="#000"><span /></font>
																</td>
																<td><input hidden id="customerId" value="${date.data.rows[i].customerId}" /> <input hidden id=nurContentId value="${date.data.rows[i].nurContentId}" />
																	<button onclick="ok(${date.data.rows[i].customerId},${date.data.rows[i].nurContentId})" class="btn btn-success">
																	<span class="glyphicon glyphicon-ok"></span>
																</button>
																	<button onclick="remove(${date.data.rows[i].customerId},${date.data.rows[i].nurContentId})" class="btn btn-danger">
																	<span class="glyphicon glyphicon-remove"></span>
																</button></td>
															</tr>
														</c:forEach>
													</c:if>

												</tbody>
											</table>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
					
					<div style="text-align: right;" mt20 ">
					<a href="nurrecord/customerList.do ">
						<button class="btn btn-success ">返回</button>
					</a>
				</div>
			</div>
		</div>
	</div>
</body>
</html>